package chat.chit.tit.mit.adapter;


import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import chat.chit.tit.mit.R;
import chat.chit.tit.mit.model.ChatContentEntity;

public class ChatAdapter extends BaseAdapter{
	
	private Context mContext;
	private List<ChatContentEntity> listContent;
	private LayoutInflater inflater;
	public ChatAdapter(Context context, List<ChatContentEntity> listContent) {
		this.mContext = context;
		this.listContent = listContent;
		this.inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return listContent.size();
	}

	@Override
	public Object getItem(int position) {
		return listContent.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("ViewHolder")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder viewHolder = null;
		if(convertView == null) {
			viewHolder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_chat_content, parent, false);
			viewHolder.icon = (ImageView) convertView.findViewById(R.id.ic_icon_person);
			viewHolder.tvContent = (TextView) convertView.findViewById(R.id.tv_content);
			viewHolder.tvFullName = (TextView) convertView.findViewById(R.id.tv_name);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		
		if(listContent.get(position).isStatus()){
			viewHolder.icon.setVisibility(View.VISIBLE);
		}else {
			viewHolder.icon.setVisibility(View.INVISIBLE);
		}
		
		viewHolder.tvContent.setText(listContent.get(position).getContent());
		viewHolder.tvFullName.setText(listContent.get(position).getFullName());
		return convertView;
	}
	
	public class ViewHolder {
		ImageView icon;
		TextView tvFullName;
		TextView tvContent;
	}

}
